//
//  YTDrvierOrderViewController.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/8/14.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTDrvierOrderViewController.h"
#import "YTPickedOrderViewCell.h"
#import "YTPickedOrderModel.h"
#import "YTDriverTeamServices.h"

@interface YTDrvierOrderViewController ()
@property (assign, nonatomic) NSInteger page;
/** 数据源*/
@property (strong, nonatomic) NSMutableArray<YTPickedOrderModel *> *dataArray;
@end

@implementation YTDrvierOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _page = 1;
    _dataArray = [NSMutableArray array];
    @weakify(self);
    [self.tableView addLoadDataControl:^{
        @strongify(self);
        self.page++;
        [self requeData];
    }];
    [self requeData];
}

/** 网络请求*/
- (void)requeData {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"page"] = [NSString stringWithFormat:@"%zd", _page];
    dict[@"driverId"] = self.driver_id;
    dict[@"orderType"] = self.order_type;
    [SVProgressHUD show];
    [[YTDriverTeamServices driverOrderList:dict] subscribeNext:^(NSDictionary *response) {
        [SVProgressHUD dismiss];
        NSDictionary *data = response[@"responseData"];
        NSArray<YTPickedOrderModel *> *array = [NSArray yy_modelArrayWithClass:[YTPickedOrderModel class]
                                                                          json:data[@"orderList"]];
        [_dataArray addObjectsFromArray:array];
        [self.tableView reloadData];
        if (array.count < 10) {
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        }
    }];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YTPickedOrderViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YTDriverOrder" forIndexPath:indexPath];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

#pragma mark - Navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
}

#pragma mark - 空数据

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *text = @"该司机还没有相关订单哟～";
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0f],
                                 NSForegroundColorAttributeName: kGrayColor};
    
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed:@"empty_order"];
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return -100;
}


@end
